#include <cstdio>
#include <iostream>
#include <cstdlib>

#define MAXN 11

using namespace std;

void swap(int *a, int *b) {
    int t = *a;
    *a = *b;
    *b = t;
}

void output(int *a, int len) {
    for (int i = 0; i < len - 1; i++)
    {
        cout << *(a + i) << ",";
    }
    cout << *(a + len - 1) << endl;
}

void fun(int *a, int s, int len) {
    if (s == len - 1)
        output(a, len);
    else {
        for (int i = s; i < len; i++) {
                swap(a + i, a + s);
                fun(a, s + 1, len);
                swap(a + i, a + s);
             
        }
    }

}

int main() {
    cout << "Input" << endl;
    int a[MAXN];
    int len = 0;
    int t;
    while (cin >> t) {
        if (t == 0)
            break;
        a[len++] = t;
    }
    
    cout << "Output" << endl;
    fun(a, 0, len);
    cout << "End" << endl;
    return 0;
}